<?php
     @session_start();
    include("template/head.php");
  //  include("template/menu_left.php");   
   // include("submit/Articles/test_qte.php");
?>
<script>
function showArticle()
{
	artile_id = emp = document.getElementById("select01");
	id=artile_id.options[artile_id.selectedIndex].value;
	 var xhReq = new XMLHttpRequest();
	 xhReq.open("GET", "ajax/getArticle.php?q="+id, false);
	 xhReq.send(null);
	 var serverResponse = xhReq.responseText;
 if(serverResponse!=""){
    var array = [];
	array = JSON.parse(serverResponse);
	// Add Fournisseur
	frn = document.getElementById("id_fournisseur");
	var lengthFournisseur = frn.options.length;
    for(i = 0; i < lengthFournisseur; i++)
    {
      // check the current option's text if it's the same with the input box
      if (frn.options[i].value == array.fournisseur)
      {
         frn.selectedIndex = i;
         break;
      }     
    }
	console.log(">>>>>>>>>>>>>>>>>>>>>"+array);
	document.getElementById('designation').value = array.designation;
	// Add Unité de stockage
	unit = document.getElementById("unit");
	var lengthUnit = unit.options.length;
    for(i = 0; i < lengthUnit; i++)
    {
      // check the current option's text if it's the same with the input box
      if (unit.options[i].value == array.unit_stock)
      {
         unit.selectedIndex = i;
         break;
      }     
    }
	// Add Devise
	devise = document.getElementById("type_monnaie");
	var lengthDevise = devise.options.length;
    for(i = 0; i < lengthDevise; i++)
    {
      // check the current option's text if it's the same with the input box
      if (devise.options[i].value == array.devise)
      {
         devise.selectedIndex = i;
         break;
      }     
    }
 }
}
</script>
 <style>
        	input[type="text"]{
        		height:30px !important;
        	}
        </style>
    <div class="container-fluid">
        <div class="row-fluid">
                
        <?php include("template/menu_left.php") ?>                
        
        <div class="span10" id="content">
            <div class="row-fluid">
            <!-- block -->
                <!--  ************************ ROW ************************  -->
              <div class="span12">   
                 <div class="block">
                    <div class="navbar navbar-inner block-header">
                        <div class="muted pull-left">Ajouter une entrée</div>
                        <!-- .toolbar -->
                    </div>   
                    <div class="block-content collapse in" id="div-1">
                    <form id="formAddIntervention" class="form-horizontal"  enctype="multipart/form-data" method="POST" action="submit/entree/add_entree.php">	
                    <div class="control-group">  
                        <label class="control-label span4" for="ref_article">Réference Article</label>
                          <div class="controls">
                                    <select class="validate[required] form-control chzn-select" id="select01" name="ref_article" onchange="showArticle()">
                                    <option value="">Selectionner</option>
                                   	<?php
                                            $table = "SELECT DISTINCT (`ref_article`), `id_article`, `photo_name` FROM st_article ORDER BY id_article ASC;";     
                                            $colonne = mysql_query($table);     
                                            while($data = mysql_fetch_array($colonne)){
                                            echo '<option value="'.$data["id_article"].'">'.$data["ref_article"].'</option>';
                                            }
                                    ?>
                                    </select>	
                          </div>
                    </div>
                    <div class="control-group">
                        <label for="comment" class="control-label span4"  for="pass1">Désignation</label>
                    	<div class="controls">
                    		<textarea name="designation" class="validate[required,custom[integer]] form-control span5" placeholder="Désignation" id="designation" disabled></textarea>
                       </div>
                    </div>
                   
                    <div class="control-group">  
                            <label class="control-label span4" for="id_fournisseur">Fournisseur</label>
                            <div class="controls">
	                            <select id="id_fournisseur" class="validate[required] form-control chzn-select" name="id_fournisseur">
                                        <option value="">Selectionner</option>
                                            <?php
                                            $table = "SELECT DISTINCT (`raison_social`), `id_fournisseur` FROM st_att_fournisseur ORDER BY nom_fournisseur ASC;";     
                                            $colonne = mysql_query($table);     
                                            while($data = mysql_fetch_array($colonne)){
                                                    echo '<option value="'.$data["id_fournisseur"].'">'.$data["raison_social"].'</option>';
                                            }
                                            ?>
                                     </select> 
                            </div>
                    </div>      
               
                    <div class="control-group">  
                        <label class="control-label span4" for="ref_article">Quantité</label>
                          <div class="controls">
                            <input type="text" name="qte" class="validate[required] form-control" placeholder="Quantité" id="form-validation-field-1">
                         	
                         	<select id="unit" class="validate[required] form-control span2" name="unit" disabled style="margin: 0 0 0 14px;">
            					<option value=""></option>
              						<?php
									$table = "SELECT DISTINCT (`valeur`), `id_unite_stockage` FROM st_att_unite_stockage ORDER BY nb_pieces ASC;";     
									$colonne = mysql_query($table);     
									while($data = mysql_fetch_array($colonne)){
									echo '<option value="'.$data["id_unite_stockage"].'">'.$data["valeur"].'</option>';
									}
							 	  ?>
							</select>
                          </div>
                    	</div>
                    	
                    	<div class="control-group">
                            <label for="comment" class="control-label span4">Prix Achat TND</label>
                            <div class="controls">
                          	<input type="text" name="prix" class="validate[required,custom[number]] form-control" placeholder="Prix d'achat" id="form-validation-field-3">
                            </div>
                        </div>
                        <div class="control-group">  
                        <label class="control-label span4" for="ref_article">Prix Achat Devise</label>
                          <div class="controls">
                            <input type="text" name="prix_en_devise" class="form-control" placeholder="Prix en devise" id="form-validation-field-1">
                         	
                         	<select id="unit" class="form-control span2" name="id_monnaie" style="margin: 0 0 0 14px;">
                                    <option value="">Selectionner</option>
                                    <?php
                                        $table = "SELECT DISTINCT `nom_monnaie`, `id_monnaie` FROM st_att_monnaie";     
                                        $colonne = mysql_query($table);     
                                        while($data = mysql_fetch_array($colonne)){
                                        echo '<option value="'.$data["id_monnaie"].'">'.$data["nom_monnaie"].'</option>';
                                        }
                                   ?>
                                </select>
            		
                          </div>
                    	</div>
                        <div class="control-group">
                            <label for="comment" class="control-label span4">Date Ajout</label>
                            <div class="controls">
                              <input type="text" data-color-format="rgb" data-color="rgb(255, 146, 180)" data-date-format="dd/mm/yyyy" name="dateAdd" id="date01" class="datepicker" value="<?php echo date('d/m/Y'); ?>">
                            </div>
                        </div>
                        <div class="control-group">
                            <label for="comment" class="control-label span4">Note</label>
                            <div class="controls">
                          	<textarea id="comment" name="comment" placeholder="Mettez votre note ici..." class="span8"></textarea>
                            </div>
                        </div>  
                             <!-- /.control-group -->
                    </div>
                    </div>
              </div>
            <!--  ************************ / ROW ************************  -->
            
              <div class="span12" style="margin-left:0px;">
              <div class="form-group">
                <div class="col-lg-8">
                    <input type="submit" value="Ajouter" class="validate[required] span3 btn btn-primary" style="margin-bottom:1em; float: right;" name="marque_ajout">
               </div>
          </div>         
             </form>   
            </div>
          
          </div>
            <hr>
        </div>
<?php  include("template/footer_vente_achat.php") ; ?>